package com.aifund.app.controller;

import com.aifund.app.entity.form.feedback.SubmitFeedbackForm;
import com.aifund.app.service.FeedbackService;
import com.aifund.common.entity.Feedback;
import com.aifund.common.enums.feedback.FeedbackStatusEnum;
import com.aifund.common.result.ResultBody;
import com.aifund.common.util.JwtUtil;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 意见反馈
 */
@Api(tags = "反馈意见")
@RestController
@RequestMapping("/api/feedback")
public class FeedBackController {

    @Autowired
    FeedbackService feedbackService;
    @Autowired
    JwtUtil jwtUtil;

    /**
     * 提交反馈意见
     * @param form
     * @param request
     * @return
     */
    @ApiOperation(value = "提交反馈意见")
    @PostMapping("/submitFeedback")
    public ResultBody submitFeedback(@RequestBody @Validated  SubmitFeedbackForm form, HttpServletRequest request){
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(form,feedback);
        feedback.setUserId(jwtUtil.getUserId(request));
        List<String> imgs = form.getFeedbackImages();
        feedback.setFeedbackImages(JSON.toJSONString(imgs));
        feedback.setStatus(FeedbackStatusEnum.WAIT_AUDIT.getStatus());
        feedbackService.save(feedback);
        return ResultBody.success();
    }

}
